#include "Comm.hpp"
#include <unistd.h>
int main()
{
    Fifo fifo(Path);
    // 建立读端
    int rfd = open(Path, O_RDONLY);
    if (rfd < 0)
    {
        cerr << "open fail,errno:" << errno << ",errstring:" << strerror(errno) << endl;
        return 1;
    }
    //如果我们写端没有打开，读先打开，open就会阻塞等待，直到写端打开，读open才会返回
    cout<<"open success"<<endl;
    char buffer[1024];
    while (true)
    {
        ssize_t n = read(rfd, buffer, sizeof(buffer) - 1);
        if (n > 0) // 成功读取
        {
            buffer[n] = 0;
            cout << "Client Say :" << buffer<<endl;
        }
        else if (n == 0)
        {
            cout << "Client Quit,me too" << endl;
            break;
        }
        else
        {
            cerr << "read fail,errno:" << errno << ",errstring:" << strerror(errno) << endl;
            break;
        }
    }
    sleep(1);
    return 0;
}